<?php
$_syspause = 1;
require_once($_SERVER['DOCUMENT_ROOT']."/defaultconf.mex");
MYTCONN();
	$Total = 0;

	$GET = $GLOBALS['MYT']->db_array("SELECT becID, becQuant, becMoney, NAME, OriNombre, CliNombre, CliTelefono, CliTelefono2, CliDomicilio, CliPisoPuerta, CliPortal, CliCP, CiuCiudad FROM bonusencomendas
	INNER JOIN clientes ON becClient = CliNumero
	INNER JOIN origenes ON OriNumero = becOffice
	INNER JOIN ciudades ON CliCiudad = CiuNumero
	INNER JOIN bonusproducts ON REF = becProduct
	WHERE DATE(becDateRequest) = DATE_SUB(CURRENT_DATE, INTERVAL 1 DAY) AND becFlag = 2");
if($GET[0]>0) {
	#do_mail 
	$GETMAddress = $GLOBALS['MYT']->db_array("SELECT smb_CttEmail FROM systemoffice.staff_members 
					WHERE smb_ID IN (1,125,80)");
					
			$_sysMailTopic = "TUGA PT - Sistema de Pontos, Nota de Encomenda de pr�mios de cart�o {$sysTime}";
			$HTML = $_sysMailTopic."<br />";
		for($i=1;$i<=$GET[0];$i++) {
			$HTML .= "
			----------------------------------------------------------------------------------------<br />
			Pr�mio: {$GET[$i]['NAME']}<br />
			Cliente: {$GET[$i]['CliTelefono']}<br />
			Telefone: {$GET[$i]['CliTelefono']}<br />
			Telemovel: {$GET[$i]['CliTelefono2']}<br />
			Morada: {$GET[$i]['CliDomicilio']}, n. {$GET[$i]['CliPortal']} {$GET[$i]['CliPisoPuerta']}<br />
					{$GET[$i]['CliCP']} {$GET[$i]['CiuCiudad']}<br />
			Quantidade: {$GET[$i]['becQuant']} unidade(s)<br />
			Custo Unitario: {$GET[$i]['becMoney']} Euros<br />";
			$Total += $GET[$i]['becMoney'];
		}
		$HTML .= "
			----------------------------------------------------------------------------------------<br />
			Total Geral: ".number_format($Total,2)." Euros";
	$_sysSenderName = 'Relatorio Tuga';
	$ATTCH = '';
	#if (file_exists($ATTCH)) { 
	#}
	for($r=1;$r<=$GETMAddress[0];$r++) {
		authmail('<no-reply@moneyexpress.pt>','ASD',$GETMAddress[$r]['smb_CttEmail'],$_sysSenderName,$_sysMailTopic,'',$HTML,$ATTCH,$_sysconfMailString);
	}
}